require 'gnuplot'

class F6

 def initialize(inicio, fim)
 	@inicio = inicio
 	@fim = fim
 end
 
 def calcula(x)
 	sum = 0
 	(1..10).each do |e|
 		sum += (-1)*(x+e)*Math.sin(Math.sqrt((x+e).abs))
 	end
 	(10 * 4189.8291)+ sum 
 end
 
 def valores_range
 	@arr = []
 	(@inicio..@fim).each do |v|
 		@arr << self.calcula(v)
 	end
 	return @arr
 end
 
 def plotar
 	
 	Gnuplot.open do |gp|
  		Gnuplot::Plot.new( gp ) do |plot|
  
    	plot.title  "F6"
    	plot.xlabel "X"
    	plot.ylabel "F6(X)"
    
    	x = (@inicio..@fim).collect { |v| v.to_f }
    	y = x.collect { |v| self.calcula(v) }

    	plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds|
      		ds.with = "linespoints"
    	  	ds.notitle
	    end
	  end
	end
 	
 end
end
